package com.happy.main.config.redis;

/**
 * @program: happy-shopping-op
 * @description: redis队列消费者配置
 * @author: taoxinhuan
 * @create: 2020-04-26 20:49
 **/

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;


@Service
@Slf4j
public class Subscriber extends Thread {
    @Autowired
    RedisTemplate<String, Message> redisTemplate;


    @Override
    public void run() {
        while (true) {
            log.info(this.getId()+"：已经启动");
            try {
                sleep(10000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Message message = redisTemplate.opsForList().rightPop("queue", 1000L, TimeUnit.SECONDS);
            System.out.println("接收到了" + message);
        }
    }
}
